/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"FF4E3FBF-A95D-4184-8C3B-FBE50FC78653"}
 * @AllowToRunInFind
 */
function onAction_consulta(event) {
	controller.find()
	
	var $desde = new Date(globals.gAnio,globals.gMes-1,1)
	var $hasta = new Date(globals.gAnio,globals.gMes,0)
	
	fecha = '#' + utils.dateFormat($desde,'dd-MM-yyyy') + '...' + utils.dateFormat($hasta,'dd-MM-yyyy') + '|dd-MM-yyyy'
		
	controller.search()
}

/**
 * Callback method for when form is shown.
 *
 * @param {Boolean} firstShow form is shown first time after load
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"ADAF20CA-BD6C-4FFA-B692-3253DEFA8A55"}
 * @AllowToRunInFind
 */
function onShow(firstShow, event) {
	controller.loadRecords(null)
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"4C227115-79F3-427C-B827-3FAA11336E50"}
 */
function onAction_modificar(event) {
	globals.gboton = event.getElementName()
	forms.asiento_cab_modif.controller.loadRecords(asiento_cab_id)
	globals.formEnVentana('asiento_cab_modif','ASIENTO','Modificación de Asiento')
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"6AC61CFA-D477-43FF-8044-8B61AA9D2050"}
 */
function onAction_cop_rev(event) {
	/** @type {JSFoundSet<db:/contable/limbo_cab>}*/
	var fs_limbo = databaseManager.getFoundSet('contable','limbo_cab')
	databaseManager.setAutoSave(false)
    fs_limbo.newRecord()	
	fs_limbo.moneda			 	= moneda
	fs_limbo.letra 				= letra
	fs_limbo.tipo_actualizacion	= globals.z_conf_asiento_normal
	fs_limbo.fecha 				= fecha
	fs_limbo.texto 				= texto
	fs_limbo.dolar 				= dolar
	fs_limbo.empresa 			= globals.gUservID
	fs_limbo.hizo 				= globals.glegajo
	fs_limbo.moneda_carga 		= moneda_carga
	fs_limbo.total 				= total
	globals.gtotal_debe 		= 0
    globals.gtotal_haber 		= 0
	var $cant = databaseManager.getFoundSetCount(asiento_cab_to_asiento)
	for (var i = 1 ; i <= $cant ; i++)
	{
		asiento_cab_to_asiento.setSelectedIndex(i)
		fs_limbo.limbo_cab_to_limbo.newRecord()
		fs_limbo.limbo_cab_to_limbo.centro 		= asiento_cab_to_asiento.centro
		fs_limbo.limbo_cab_to_limbo.cuentas_id 	= asiento_cab_to_asiento.cuentas_id
		fs_limbo.limbo_cab_to_limbo.division 	= asiento_cab_to_asiento.division
		fs_limbo.limbo_cab_to_limbo.impodol 	= asiento_cab_to_asiento.impodol
		fs_limbo.limbo_cab_to_limbo.importe 	= asiento_cab_to_asiento.importe
		fs_limbo.limbo_cab_to_limbo.leycod 		= asiento_cab_to_asiento.leycod
		fs_limbo.limbo_cab_to_limbo.leyenda	 	= asiento_cab_to_asiento.leyenda
		fs_limbo.limbo_cab_to_limbo.columna 	= asiento_cab_to_asiento.columna
	}
	var estado = databaseManager.saveData()
	if (estado == false)
	{
		globals.DIALOGS.showWarningDialog("Aviso","No se actualizaron los datos","Ok")
		databaseManager.revertEditedRecords()
		return			
	}
	forms.asiento_cab_cop_rev.controller.loadRecords(fs_limbo.limbo_cab_id)
	globals.formEnVentana('asiento_cab_cop_rev','ASIENTO','Copiar/Revertir Asiento')
}

/**
 * Handle changed data.
 *
 * @param {String} oldValue old value
 * @param {String} newValue new value
 * @param {JSEvent} event the event that triggered the action
 *
 * @returns {Boolean}
 *
 * @properties={typeid:24,uuid:"FAF4F5D6-93B7-4BCF-A448-B8087FF23DEB"}
 */
function onDataChangeFecha(oldValue, newValue, event) {
	globals.gMes 	= newValue.substring(0,newValue.indexOf('|'))
	globals.gAnio	= newValue.substring(newValue.indexOf('|')+1,newValue.length)
	return true
}
